<?php
class SysAction extends CommonAction {
	private $Sys;

	public function __construct(){
		parent::__construct();
	    $this->Sys=D('Sys');
	}

    public function index(){
		$value=$this->Sys->find();
		$this->assign($value);
		$this->display('./Tpl/Admin/Sys.html');
    }
	public function trade(){
		$value=$this->Sys->find();
		$this->assign($value);
	
	
    $this->display("./Tpl/Admin/trade.html");
	}
	public function update(){
		if(empty($_POST['id'])){
		   $this->error('对不起，您没有权限！');
		}
		$data['id']=$_POST['id'];
		if(!empty($_POST['title'])){
		$data['title']=$_POST['title'];
		}
		if(!empty($_POST['key'])){
		$data['key']=$_POST['key'];
		}
		if(!empty($_POST['des'])){
			
        $data['des']=$_POST['des'];
		}
		if(!empty($_POST['copy'])){
		$data['copy']=$_POST['copy'];
		}
		if(!empty($_POST['code'])){
		$data['code']=$_POST['code'];
		}
		if(!empty($_POST['email'])){
		$data['email']=$_POST['email'];
		}
		if(!empty($_POST['pwd'])){
		$data['pwd']=$_POST['pwd'];
		}
		if(!empty($_POST['auth'])){
		$data['auth']=$_POST['auth'];
		}
		if(!empty($_POST['invitfen'])){
		$data['invitfen']=$_POST['invitfen']/100;
		}
		if(!empty($_POST['drawfee'])){
		$data['drawfee']=$_POST['drawfee'];
		}
		if(!empty($_POST['tradefee'])){
		$data['tradefee']=$_POST['tradefee'];
		}
		if(!empty($_POST['qq'])){
		$data['qq']=$_POST['qq'];
		}
		if(!empty($_POST['qqqun'])){
		$data['qqqun']=$_POST['qqqun'];
		}
		if(!empty($_POST['tel'])){
		$data['tel']=$_POST['tel'];
		}
		if(!empty($_POST['addr'])){
		$data['addr']=$_POST['addr'];
		}
		if(!empty($_POST['icp'])){
		$data['icp']=$_POST['icp'];
		}
		if(!empty($_POST['alipay'])){
		$data['alipay']=$_POST['alipay'];
		}
		if(!empty($_POST['alipay_name'])){
		$data['alipay_name']=$_POST['alipay_name'];
		}
		if(!empty($_POST['alipaypwd'])){
		$data['alipaypwd']=$_POST['alipaypwd'];
		}
		if(isset($_POST['ks'])){
		$data['ks']=$_POST['ks'];
		}
		if(isset($_POST['kuangopen'])){
		$data['kuangopen']=$_POST['kuangopen'];
		}
		if(!empty($_POST['zhangting'])){
		$data['zhangting']=$_POST['zhangting'];
		}
		if(!empty($_POST['dieting'])){
		$data['dieting']=$_POST['dieting'];
		}
		if(!empty($_POST['shichang_shouxufei'])){
		$data['shichang_shouxufei']=$_POST['shichang_shouxufei']/100;
		}
		if(isset($_POST['jishiopen'])){
			$data['jishiopen']=$_POST['jishiopen'];
		}
		if(isset($_POST['hongbao'])){
			$data['hongbao']=$_POST['hongbao'];
		}
		
		if(isset($_POST['ksname'])){
			$data['ksname']=$_POST['ksname'];
		}
	
		if(!empty($_POST['kgname'])){
			$data['kgname']=$_POST['kgname'];
		}
		
		if($_FILES["logo"]["tmp_name"]){
			move_uploaded_file($_FILES["logo"]["tmp_name"],"upload/" . $_FILES["logo"]["name"]);
			$data['logo'] = "upload/" . $_FILES["logo"]["name"];
		}else{
		    $data['logo'] = $_POST['logoimg'];
		}

		if($this->Sys->save($data)!==false){
		    $this->success('修改成功！');
		}else{
		    $this->error('修改失败！');
		}
    }
    
    
    public function admin_bank_list(){
        $list=M("Bank_admin")->select();
        $this->assign("list",$list);
        $this->display('./Tpl/Admin/Admin_Bank_list.html');
    }
    public function admin_bank_add(){
        $id=intval($_GET['id']);
        if(!empty($id)){
           $bank= M("Bank_admin")->where("id='$id'")->find();
           $this->assign("bank",$bank);
        }
        $this->display('./Tpl/Admin/Admin_Bank_add.html');
    }
    public function admin_bank_add_ok(){
        $id=intval($_POST['id']);
        if(empty($_POST['cardname'])){
            $this->error('请输入银行卡姓名');
        }
        if(empty($_POST['bankname'])){
            $this->error('请输入银行类型');
        }
        if(empty($_POST['address'])){
            $this->error('请输入银行地址');
        }
        if(empty($_POST['cardnum'])){
            $this->error('请输入银行卡号');
        }
        $data['cardname']=$_POST['cardname'];//银行卡姓名
        $data['bankname']=$_POST['bankname'];//银行类型
        $data['address']=$_POST['address'];//银行地址
        $data['cardnum']=$_POST['cardnum'];//银行卡号
        if(empty($id)){
           $re= M("Bank_admin")->add($data);
        }else{
          $re=  M("Bank_admin")->where("id='$id'")->save($data);
        }
        if($re){
            $this->success("添加成功","?s=Admin/Sys/admin_bank_list");
        }else{
            $this->error("添加失败");
        }
    }
    public function admin_bank_delete(){
        $id=intval($_GET['id']);
       $re= M("Bank_admin")->where("id='$id'")->delete();
       if($re){
           $this->success("删除成功","?s=Admin/Sys/admin_bank_list");
       }else{
           $this->error("删除失败");
       }
    }
}